﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data;

namespace Itegracion.Framework.Forms
{
    public static class Expander
    {
        public static DataGridView AddTextBoxColumn(this DataGridView grid, string headerText, string dataPropertyName, int width, string format)
        {
            DataGridViewTextBoxColumn field = new DataGridViewTextBoxColumn();
            field.Name = dataPropertyName;
            field.HeaderText = headerText;
            field.DataPropertyName = dataPropertyName;
            field.Width = width;
            if (format != null) {
                field.DefaultCellStyle.Format = format;
            }

            grid.Columns.Add(field);
            return grid;
        }
        public static DataGridView AddTextBoxColumn(this DataGridView grid, string headerText, string dataPropertyName, int width) {
            return AddTextBoxColumn(grid, headerText, dataPropertyName, width, null);
        }
        public static DataGridView AddTextBoxColumn(this DataGridView grid, string headerText, int width)
        {
            return AddTextBoxColumn(grid, headerText, headerText, width);
        }

        public static List<Element> ToList(this DataRowCollection rows) {
            List<Element> rpta = new List<Element>();
            
            if(rows.Count > 0)
                foreach (object item in rows[0].ItemArray)
                {
                    rpta.Add(new Element("rpta", item));
                }

            return rpta;
        }
    }
}
